package com.easy.easylibdemo.ui.greendao.model;

import com.easy.easylibdemo.gen.SearchRecordBeanDao;
import com.easy.easylibdemo.ui.greendao.utils.GreenDaoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 作　　者: guyj
 * 修改日期: 2017/2/10
 * 描　　述:
 * 备　　注:
 */

public class SearchRecordImpl implements SearchRecordModel{

    private List<SearchRecordBean> beans;
    private List<SearchRecordBean> filterBeans;
    private SearchRecordBeanDao searchRecordBeanTable;

    @Override
    public List<SearchRecordBean> getSearchRecords() {
        searchRecordBeanTable= GreenDaoUtils.getInstance().getDaoSession().getSearchRecordBeanDao();
        beans=searchRecordBeanTable.loadAll();
        return beans;
    }

    /**
     * 过滤列表内容
     * @param list
     * @param queryText
     * @return
     */
    @Override
    public List<SearchRecordBean> filterQuery(List<SearchRecordBean> list, String queryText) {
        if (filterBeans==null){
            filterBeans=new ArrayList<SearchRecordBean>();
        }else{
            filterBeans.clear();
        }
        for (SearchRecordBean bean:list
                ) {
            if (bean.getSearchRecord().contains(queryText)){
                filterBeans.add(bean);
            }
        }
        return filterBeans;
    }

    @Override
    public List<SearchRecordBean> filterAdd(String addStr) {
        return null;
    }
}
